extends CharacterBody2D

signal rock_entered
var rocks_array = [preload("res://textures/Rocks/rock.png"),
 preload("res://textures/Rocks/rockGrass.png"),
 preload("res://textures/Rocks/rockIce.png"),
 preload("res://textures/Rocks/rockSnow.png")]
const SPEED = 100.0
var rock_type_index:int = 0
var is_drop:int = randi_range(0,1) # 冰柱是否会掉下来

# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")

func _ready():
	rock_type_index = Global.next_ground_type
	%Rock.set_texture(rocks_array[rock_type_index])

func _physics_process(delta):
	velocity.x -= SPEED * delta
	# 如果是冰柱，而且是在上方，则可能会往下掉
	if rock_type_index == 2 and rotation_degrees == -180 and is_drop == 1:
		velocity.y += SPEED/2 *delta
	move_and_slide()
	if position.x <=-%Rock.texture.get_size().x:
		queue_free()
		


func _on_area_2d_body_entered(body):
	if body.is_in_group("plane"):
		rock_entered.emit()
